package servlet;

import dao.Load;
import po.Linkman;
import po.Type;
import po.User;

import java.util.ArrayList;

public class Loading {

    public User loadUser(User user){
        new Load().loading(user);
        user.check();
        return user;
    }

    public ArrayList<Type> loadType(int uid,ArrayList<Type> type){
        type=new Load().loadingType(uid);
        return type;
    }

    public ArrayList<Linkman> selectLinkmen(String type, String[] condition, int uid){
        ArrayList<Linkman> tmp;
        String sql=" ";
        if(!condition[0].equals("%")){
            sql=sql+"&& name='"+condition[0]+"' ";
        }
        if(!condition[1].equals("%")){
            sql=sql+"&& sex='"+condition[1]+"' ";
        }
        if(!condition[2].equals("%")){
            sql=sql+"&& phone='"+condition[2]+"' ";
        }
        if(!condition[3].equals("%")){
            sql=sql+"&& e_mail='"+condition[3]+"' ";
        }

        if (type==null){
            tmp=new Load().loadingLinkmen(uid,sql);
        }else {
            tmp=new Load().loadingLinkmen(uid,type,sql);
        }

        if (tmp!=null){
            for (int i=0;i<tmp.size();i++){
                new Load().loadingTypeToLink(tmp.get(i));
            }
        }
        return tmp;
    }

}
